
package com.fly.demo;

import java.util.Scanner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;

import com.fly.demo.auto.RedisConfig;
import com.fly.demo.auto.ReloadConfig;

/**
 * 
 * SpringBoot 启动入口
 * 
 * @author 00fly
 * @version [版本号, 2018年7月20日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@SpringBootApplication
public class Application implements CommandLineRunner
{
    private Logger log = LoggerFactory.getLogger(getClass());
    
    public static void main(String[] args)
    {
        SpringApplication.run(Application.class, args);
    }
    
    @Autowired
    RedisConfig redisConfig;
    
    @Autowired
    ReloadConfig reloadConfig;
    
    @Override
    public void run(String... args)
        throws Exception
    {
        String input;
        Scanner sc = new Scanner(System.in);
        do
        {
            reloadConfig.refresh(redisConfig);
            log.info("redisConfig por={}", redisConfig.getPort());
            log.info("------------输入q退出,输入其他值继续运行------------");
            input = StringUtils.trimAllWhitespace(sc.nextLine());
        } while (!input.equalsIgnoreCase("q"));
        log.info("----------系统退出成功----------");
        sc.close();
    }
}
